package com.example.navigationdemo

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.navigation.NavController
import androidx.navigation.Navigation
import androidx.navigation.ui.NavigationUI

class MainActivity : AppCompatActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        //注意：该布局文件id---是NavHostFragment的id
        val navController:NavController=Navigation.findNavController(this,R.id.fragment)
        //显示左上角返回键
        NavigationUI.setupActionBarWithNavController(this,navController)
    }

    //设置左上角返回键的点击
    override fun onSupportNavigateUp(): Boolean {
        return Navigation.findNavController(this,R.id.fragment)
            .navigateUp()

    }
}
